import requests
from lxml import etree

url='http://angelimg.spbeen.com'

headers = {
    "Referer": 'http://angelimg.spbeen.com/',
}

response = requests.get(url)
html = etree.HTML(response.text)
# print(html)

image_links = html.xpath('.//img/@src')

with open('images.txt', mode='w', encoding='utf-8') as file:
    for link in image_links:
        file.write(link)
        file.write('\n')

# for index, link in enumerate(image_links, start=1):
#     imagename = link.split('/')[-1]
#
#     filename = "images/{}_{}".format(index, imagename)
#     # print(filename, link)
#     try:
#         image_response = requests.get(link, headers=headers)
#         with open(filename, mode='wb') as image:
#             image.write(image_response.content)
#         print(index, 'success', link)
#     except:
#         print(index, 'error', link)